package com.yoda.mall.admin.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yoda.mall.api.HomeAdvertiseApi;
import com.yoda.mall.model.entity.sms.HomeAdvertise;
import com.yoda.mall.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class AdvertiseService {
    @DubboReference
    private HomeAdvertiseApi homeAdvertiseApi;

    public void createAdvertise(HomeAdvertise homeAdvertise) {
        homeAdvertiseApi.createAdvertise(homeAdvertise);
    }

    public void deleteAdvertise(List<Long> ids) {
        homeAdvertiseApi.deleteAdvertiseByIds(ids);
    }

    public PageResult<HomeAdvertise> advertiseList(LocalDateTime endTime, String name, Integer type, Integer pageNum, Integer pageSize) {
        Page<HomeAdvertise> page = homeAdvertiseApi.getAdvertiseListPage(endTime, name, type, pageNum, pageSize);
        return new PageResult<>((int) page.getCurrent(), (int) page.getSize(), (int) page.getTotal(), page.getRecords());
    }

    public void updateAdvertiseStatus(Long id, Integer status) {
        HomeAdvertise homeAdvertise = new HomeAdvertise();
        homeAdvertise.setId(id);
        homeAdvertise.setStatus(status);
        homeAdvertiseApi.updateAdvertise(homeAdvertise);
    }

    public void updateAdvertise(Long id, HomeAdvertise homeAdvertise) {
        homeAdvertise.setId(id);
        homeAdvertiseApi.updateAdvertise(homeAdvertise);
    }

    public HomeAdvertise getAdvertise(Long id) {
        return homeAdvertiseApi.getAdvertiseById(id);
    }
}
